package baoliDigui;

import java.util.ArrayList;

/*
* 规定1和A对应  2和B对应......
* 那么一个数字字符串 比如"111",就可以转化为"KA" "AAA" "AK"
* 给定一个只有数字的字符串  返回有多少种转化结果
* */
public class Trans {
    public static void main(String[] args) {
        String str="1212";
        ArrayList<Character> arrayList = new ArrayList<>();
        for (char c: str.toCharArray()){
            arrayList.add(c);
        }
        System.out.println(intToChar(arrayList));
    }

    public static int intToChar(ArrayList<Character> arrayList){
        if (arrayList.size()==1){
            return 1;
        }
        if (arrayList.size()==2){
            if (isNumber(arrayList.get(0),arrayList.get(1))){
                return 2;
            }else {
                return 1;
            }
        }
        int len=arrayList.size();
        //判断最后两位能否组成一个数字

        //如果可以  则组成方式的数量为arr-1 和 arr -2 的组成量
        if (isNumber(arrayList.get(len-1),arrayList.get(len-2))){
            arrayList.remove(arrayList.size()-1);

            System.out.println("|"+arrayList.size());

            int res1=intToChar(new ArrayList<Character>(arrayList));

            System.out.println(arrayList.size());

            arrayList.remove(arrayList.size()-1);

            System.out.println("//"+arrayList.size());

            return res1+intToChar(new ArrayList<Character>(arrayList));
        }else {   //如果后两位不能组成  则为len-1的组成量
            arrayList.remove(arrayList.size()-1);
            return intToChar(new ArrayList<Character>(arrayList));
        }
    }

    public static boolean isNumber(char a1,char b1){
        String a= String.valueOf(a1);
        String b= String.valueOf(b1);
        int res=Integer.parseInt(b+a);
        return  (0<res && res<26) ? true : false;
    }
}
